import React, {useImperativeHandle} from "react";
import {Form, Input, Radio} from 'antd';

import {CreateOrEditActionRef} from "vendor/components/pro-table-native";
import {EnumStatus} from "@/components/app/commonSystemSetting/constants";

const layout = {
    labelCol: {span: 6},
    wrapperCol: {span: 16},
};

const CreatePost = React.forwardRef<CreateOrEditActionRef, { rowKey: string | number, values: any }>((props, actionRef) => {
    const [form] = Form.useForm();

    useImperativeHandle(actionRef, () => ({
        getFormData: () => new Promise((resolve, reject) => {
            form.validateFields().then((data) => {
                resolve(data);
            }).catch((e) => {
                reject(new Error("请检查参数"));
            });
        })
    }));

    return (
        <Form
            initialValues={Object.assign({status: EnumStatus[0].value},props.values)}
            form={form}
            {...layout}
        >
            <Form.Item
                label="岗位编码"
                name="postCode"
                rules={[{required: true, message: '岗位编码!'}, {max: 30, message: '岗位编码不能超过30个字！'}]}
            >
                <Input placeholder="请输入岗位编码"/>
            </Form.Item>
            <Form.Item
                label="岗位名称"
                name="postName"
                rules={[{required: true, message: '岗位名称!'}, {max: 30, message: '岗位名称不能超过30个字！'}]}
            >
                <Input placeholder="请输入岗位名称"/>
            </Form.Item>
            <Form.Item
                label="岗位排序"
                name="postSort"
                rules={[{
                    required: true,
                    pattern: /[0-9]/,
                    message: "请输入正确的序号数字！"
                }, {max: 9, message: '数字不能超过9位！'}]}
            >
                <Input placeholder="请输入序号"/>
            </Form.Item>
            <Form.Item
                label="状态"
                name="status"
                rules={[{required: true, message: '情选择岗位状态!'}]}
            >
                <Radio.Group>
                    {EnumStatus.map(({label, value}) => (
                        <Radio key={value} value={value}>{label}</Radio>
                    ))}
                </Radio.Group>
            </Form.Item>
            <Form.Item
                label="备注"
                name="remark"
                rules={[{max: 150, message: '备注信息不能超过150个字！'}]}
            >
                <Input.TextArea placeholder="请输入内容"/>
            </Form.Item>
        </Form>
    )
});

export default CreatePost;